<template>
  <div class="categories-container">
    <HomeHeader />
    
    <!-- 分类标题 -->
    <div class="categories-header">
      <h1>Post Categories</h1>
    </div>

    <!-- 第一个大盒子：所有分类 -->
    <div class="categories-section">
      <div class="categories-wrapper">
        <router-link 
          v-for="category in categories" 
          :key="category.name"
          :to="category.path"
          class="category-item"
          :style="{ backgroundColor: category.bgColor }"
        >
          {{ category.name }}
          <span class="category-count">{{ category.count }}</span>
        </router-link>
      </div>
    </div>

    <!-- 第二个大盒子：雷达图表 -->
    <div class="radar-chart-section">
      <div class="chart-title">Post Categories Radar Chart</div>
      <div ref="chartRef" class="radar-chart"></div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import HomeHeader from '@/components/home-header.vue'
import * as echarts from 'echarts'

// 模拟分类数据
const categories = ref([
  { name: 'Hexo', count: 11, path: '/categories/hexo', bgColor: '#ffb7c5' },
  { name: '小故事', count: 2, path: '/categories/stories', bgColor: '#ddb7e6' },
  { name: 'win10教活', count: 1, path: '/categories/win10', bgColor: '#a8e6cf' },
  { name: 'office激活', count: 1, path: '/categories/office', bgColor: '#b7e6e6' },
  { name: '秘', count: 2, path: '/categories/secret', bgColor: '#ffe7ac' },
  { name: '诗词', count: 1, path: '/categories/poetry', bgColor: '#e6e6fa' },
  { name: '阅读', count: 1, path: '/categories/reading', bgColor: '#98fb98' },
  { name: '人情世故', count: 1, path: '/categories/life', bgColor: '#dda0dd' }
])

// 雷达图相关
const chartRef = ref(null)
let chart = null

const initChart = () => {
  const chartDom = chartRef.value
  chart = echarts.init(chartDom)
  
  const option = {
    backgroundColor: 'transparent',
    radar: {
      indicator: categories.value.map(cat => ({
        name: cat.name,
        max: 15
      })),
      shape: 'polygon',
      splitNumber: 4,
      axisName: {
        color: '#333',
        fontSize: 12
      },
      splitLine: {
        lineStyle: {
          color: ['#ddd']
        }
      },
      splitArea: {
        show: true,
        areaStyle: {
          color: ['rgba(255,255,255,0.3)', 'rgba(255,255,255,0.2)']
        }
      }
    },
    series: [{
      type: 'radar',
      data: [{
        value: categories.value.map(cat => cat.count),
        name: 'Post Count',
        lineStyle: {
          color: '#ffb7c5'
        },
        areaStyle: {
          color: 'rgba(255,183,197,0.4)'
        }
      }]
    }]
  }

  chart.setOption(option)
}

onMounted(() => {
  initChart()
  
  // 响应式调整
  window.addEventListener('resize', () => {
    chart?.resize()
  })
})
</script>

<style scoped lang="scss">
.categories-container {
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(to bottom, #fff5f5, #fff);
}

.categories-header {
  text-align: center;
  margin: 40px 0;
  
  h1 {
    font-size: 36px;
    color: #333;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  }
}

.categories-section {
  max-width: 1200px;
  margin: 0 auto 40px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.categories-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.category-item {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  border-radius: 20px;
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    filter: brightness(1.1);
  }
  
  .category-count {
    margin-left: 8px;
    background: rgba(255, 255, 255, 0.3);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 14px;
  }
}

.radar-chart-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  
  .chart-title {
    text-align: center;
    font-size: 24px;
    color: #333;
    margin-bottom: 20px;
  }
  
  .radar-chart {
    width: 100%;
    height: 400px;
  }
}
</style>
